package com.allwees.core.mq.rabbitmq;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.amqp.event.AmqpEvent;

/**
 * Mq事件基类
 *
 * @author yangylsky
 * @since 2019-11-18
 *
 */
@Getter
@Setter
public abstract class MqEvent extends AmqpEvent {
	private String key;

	public <T> MqEvent(T source) {
		super(source);
	}

	public <T> MqEvent(String key, T source) {
		super(source == null ? ObjectUtils.NULL : source);
		this.key = key;
	}

	/**
	 * 用于消息路由（bizType -> exchange），参考{@link com.allwees.core.mq.rabbitmq.config.RoutingInfo}
	 *
	 * @return
	 */
	public abstract String getBizType();

	/**
	 * 用于确定消息目的地（exchange+routingKey -> destination），参考{@link com.allwees.core.mq.rabbitmq.config.BindingInfo}
	 *
	 * @return
	 */
	public String getRoutingKey() {
		return "#";
	}

	public <T> void setSource(T source) {
		super.source = source;
	}

	public boolean isNullSource() {
		return getSource() == null || ObjectUtils.NULL.equals(getSource());
	}
}
